package com.wjy.api;

import com.wjy.dao.AuthorDao;
import com.wjy.response.ResponseBuilder;
import com.wjy.vo.Author;
import lombok.extern.log4j.Log4j2;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;

@Log4j2
@Path(value = "/author")
@Produces(value = "application/json;charset=utf-8")
public class AuthorAPI {

    private AuthorDao authorDao = new AuthorDao();

    @POST
    @Path(value = "/login")
    public Response login(@QueryParam(value = "authorAccount") String authorAccount,
                          @QueryParam(value = "authorPassword") String authorPassword) throws Exception {

        log.info("authorAccoun: " + authorAccount + " authorPassword: " + authorPassword);

        Author author = new Author(authorAccount, authorPassword);

        return ResponseBuilder.success(authorDao.login(author));

    }

    @GET
    @Path(value = "/verify")
    public Response verify(@QueryParam(value = "authorAccount") String authorAccount) throws Exception {

        log.info("authorAccount: " + authorAccount);

        return ResponseBuilder.success(authorDao.verify(authorAccount));

    }

    @PUT
    @Path(value = "/register")
    public Response verify(Author author) throws Exception {

        log.info("author: " + author.toString());

        return ResponseBuilder.success(authorDao.register(author));

    }

}
